<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: cc又瘦啦
  Date: 2021/12/20
  Time: 9:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.js"></script>
</head>
<body>

<form action="./login" method="post">

    请输入用户名:<input type="text" name="userName" id="uname"/><span id="s1"></span><br>

    请输入密码:<input type="text" name="userPwd" id="upwd"/><span id="s2"></span><br>

    <input type="button" onclick="checkoutMethod()" value="登录">

</form>

<script>
    
    function checkoutMethod() {

        var uname = $("#uname").val();
        var upwd = $("#upwd").val();

        if (uname==""){
            $("#s1").append("<input type='text' value='不允许为空'/>")
        }
        if (upwd==""){
            $("#s2").append("<input type='text' value='不允许为空'/>")
        }

        if (uname!="" && upwd!=""){
            alert(666);
            //提交判断
            $.post("selectByusername",{uname:uname},function (user) {

                if (user.userId==null){

                    $("#s1").append("<input type='text' value='用户名错误,没有此用户'/>")
                    alert("姓名为空");

                }else{
                    $.post("selectByupwd",{uname:uname,upwd:upwd},function (user) {

                        if (user.userId==null){
                            $("#s2").append("<input type='text' value='密码错误'/>")
                            alert("密码判断为空");
                        }else{
                            $("form").submit();
                        }
                    })
                }
            })
        }

    }


</script>

</body>
</html>
